package cn.liuyi.weiyi;

import org.json.JSONException;
import org.json.JSONObject;




import cn.edu.pku.tools.YJRApplication;
import cn.edu.pku.tools.YJRHttpClient;

import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

/**
 * @author vector
 *
 */
public class AppStartActivity extends Activity {
	Context context;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//去掉标题栏，注意一定要在绘制view之前调用这个方法，不然会出现//AndroidRuntimeException: requestFeature() must be called before adding content 这个错误。
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_app_start);
		context = this;
		//全屏显示
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		getInitData();
	}
	
	
	public void getInitData(){
		RequestParams params = new RequestParams(); 
		Log.v("weiyi","获取应用初始化数据开始");
		YJRHttpClient.post(context,"/data/initData.action", params, new JsonHttpResponseHandler(){
			 @Override  
	            public void onSuccess(JSONObject data) {  
						YJRHttpClient.setCookie(context); 
						YJRApplication.initData = data;
						try {
							YJRApplication.head_path = YJRApplication.server_path + data.getJSONObject("response").getJSONObject("imagePaths").getString("avatarPath");
							YJRApplication.cert_path = YJRApplication.server_path + data.getJSONObject("response").getJSONObject("imagePaths").getString("certPath");
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						Intent intent = new Intent(AppStartActivity.this, LoginActivity.class);
						startActivity(intent);
						AppStartActivity.this.finish();
	            }
		  
		});
	}
}